﻿using System.IO;
using System.Web;

namespace Ant.Interface.GlobalInfo
{
    /// <summary>
    /// 环境信息。
    /// </summary>
    public class EnvironmentInfo
    {
        static EnvironmentInfo()
        {
            var context = HttpContext.Current;
            IsWebApplication = context != null;
            if (IsWebApplication)
            {
                try
                {
                    ApplicationPhysicalPath = context.Request.PhysicalApplicationPath;
                }
                catch
                {
                    ApplicationPhysicalPath = context.Server.MapPath("~/");
                }
            }
            else
            {
                ApplicationPhysicalPath = System.Environment.CurrentDirectory;
            }

            //ApplicationPhysicalPath = IsWebApplication ? Environment.CurrentDirectory : (HttpContext.Current.Request != null ? HttpContext.Current.Request.PhysicalApplicationPath : HttpContext.Current.Server.MapPath("~/"));
            ApplicationPhysicalBin = Path.Combine(ApplicationPhysicalPath, "Bin");
            ConfigPhysicalPath = Path.Combine(ApplicationPhysicalPath, "Config");
        }

        /// <summary>
        /// 是否Web应用程序。
        /// </summary>
        public static bool IsWebApplication { get; private set; }

        /// <summary>
        /// 程序物理路径。
        /// </summary>
        public static string ApplicationPhysicalPath { get; private set; }

        /// <summary>
        /// 程序物理Bin路径。
        /// </summary>
        public static string ApplicationPhysicalBin { get; private set; }

        /// <summary>
        /// 配置物理路径。
        /// </summary>
        public static string ConfigPhysicalPath { get; private set; }
    }
}